package com.pl.action;  

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pl.bean.ResultData;
import com.pl.bean.SubSystemUserBean;
import com.pl.service.SubSystemUserService;
import com.pl.util.ResultDataUtil;

/**
 * 子系统用户
 */
@Controller
@RequestMapping(value="subuser")
public class SubSystemUserAction {
	
	
	@Autowired
	private SubSystemUserService subSystemUserService ;
	
	
	@RequestMapping(value="index")
	public String index(HttpServletRequest request,HttpServletResponse response){
		
		return "subUser/subUser";
	}
	
	@RequestMapping(value="getAll")
	@ResponseBody
	public ResultData<List<SubSystemUserBean>> getAll(HttpServletRequest request,HttpServletResponse response){
		List<SubSystemUserBean> list = subSystemUserService.getSubSystemUserBean();
		return ResultDataUtil.ok(list);
	}
	
	@RequestMapping(value="delete")
	@ResponseBody
	public ResultData<String> delete(HttpServletRequest request){
		String id = request.getParameter("id");
		subSystemUserService.deleteSubSystemUserBean(Integer.valueOf(id));
		return ResultDataUtil.ok();
	}
	
	@RequestMapping(value="addUser")
	@ResponseBody
	public ResultData<String> addUser(HttpServletRequest request){
		SubSystemUserBean ssu = new SubSystemUserBean();
		ssu.setClientName(request.getParameter("clientName"));
		ssu.setClientUrl(request.getParameter("clientUrl"));
		ssu.setUserName(request.getParameter("userName"));
		ssu.setUserPassword(request.getParameter("userPassword"));
		subSystemUserService.addSubSystemUserBean(ssu);
		return ResultDataUtil.ok();
	}
	
	@RequestMapping(value="toModify")
	@ResponseBody
	public ResultData<List<SubSystemUserBean>> toModify(HttpServletRequest request){
		SubSystemUserBean ssu = subSystemUserService.getsubSystemById(Integer.valueOf(request.getParameter("id")));
		List<SubSystemUserBean> list = new ArrayList<SubSystemUserBean>();
		list.add(ssu);
		return ResultDataUtil.ok(list);
	}

	@RequestMapping(value="modifyUser")
	@ResponseBody
	public ResultData<String> modifyUser(HttpServletRequest request){
		SubSystemUserBean ssu = new SubSystemUserBean();
		ssu.setId(Integer.valueOf(request.getParameter("id")));
		ssu.setClientName(request.getParameter("clientName"));
		ssu.setClientUrl(request.getParameter("clientUrl"));
		ssu.setUserName(request.getParameter("userName"));
		ssu.setUserPassword(request.getParameter("userPassword"));
		subSystemUserService.updateSubSystemUserBean(ssu);
		return ResultDataUtil.ok();
	}
}
